<template>
    <el-form style="width: 100%" >
        <el-row type="flex" align="top" justify="start" :gutter="20">
            <el-col :span="6">
                <el-button type="danger" @click="deleteAll" size="small">清除全部数据</el-button>
            </el-col>
            <el-col :span="6">
                <el-button type="danger" @click="deleteErrors" size="small">清除错题集</el-button>
            </el-col>
        </el-row >
        <el-row type="flex" align="top" justify="start" :gutter="20">
            <el-col :span="6">
                <input v-model="input" placeholder="请输入题号" type="number" style="height: 26px;">
                </el-col>
                <el-col :span="6">
                <el-button class="button-class" size="small" type="danger" @click="resetCurrentIndex">重置题号</el-button>
            </el-col>
        </el-row>
    </el-form>
</template>

<script>

export default {
  data () {
    return {
        input: 0
    }
  },
  components: {
  },
  computed: {
  },
  created (){
      this.getCurrentIndex()
  },
  methods: {
      getCurrentIndex(){
          let index = parseInt(window.localStorage.getItem('currentIndex'))
          this.input = index
      },
    //   重置当前题号
    resetCurrentIndex(){
        let x = parseInt(window.localStorage.getItem('maxIndex'))
        if(x > 0){
            if(this.input <= 0 || this.input > parseInt(window.localStorage.getItem('maxIndex'))){
          this.$message.error('请输入正确的题号！');
          return
        }
        window.localStorage.setItem('currentIndex',this.input)
        }else{
            this.$message.error('无存储数据！');
        }
        
    },

    //   清除全部试题
    deleteAll() {
        this.$confirm('此操作将清除全部试题数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then( () => {
            localStorage.clear()
        }
        ).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      },
    //   清除错题集
    deleteErrors() {
        this.$confirm('此操作将清除错题数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then( () => {
            localStorage.removeItem('errorIds');
        }
            
        ).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      }
  },
  mounted () {
  }
}
</script>
